package com.healthcloud.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.healthcloud.entity.IdentCorporeityResult;
import com.healthcloud.service.IdentCorporeityResultService;
import com.healthcloud.utils.ApiRes;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 体质辨识相关的服务控制器
 * 
 * @author ZhengL 2015-07-15
 */
@ApiIgnore
@Api(value = "示例说明", description = "体质辨识相关的服务控制器 ")
@RestController
@RequestMapping("/app/IdentCorporeityResult")
public class IdentCorporeityApiController {

	@Autowired
	private IdentCorporeityResultService identCorporeityResultService;

	String[] identCorporeity = { "op", "username", "usertype", "token",
			"timestamp", "v", "appid", "sign", "id", "idCard", "examId",
			"mkExamCode", "answer", "result" };

	/**
	 * 移动端上传体质辨识结果接口
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "移动端上传体质辨识结果接口",notes ="移动端上传体质辨识结果接口")
	@RequestMapping(value = "/set", method = RequestMethod.POST)
	public Object saveSurvery(HttpServletRequest request,IdentCorporeityResult ir) {
		String[] str = null;
		Map<String, String> dataMap = new HashMap();
		if(ir!=null){
			dataMap.put("mkExamCode", ir.getExamId());
			dataMap.put("answer", ir.getAnswer());
			dataMap.put("result",ir.getResult());
			dataMap.put("id", "0");
		}
		ApiRes jm = new ApiRes(identCorporeityResultService.parseJsonMap(dataMap));
		jm.setSuccess(true);
		return jm;
	}
	
	// 获取请求中的参数
	private Map<String, String> getDataMap(HttpServletRequest request,
			String[] strs) {
		Map<String, String> dataMap = new HashMap<String, String>();
		Map<String, String[]> params = request.getParameterMap();
		for(int i=0;i<strs.length;i++){
			String key = strs[i].trim().toString();
			if (params.containsKey(key)) {
				String[] values = params.get(key);
				dataMap.put(key, values[0].toString());
			}
		}
		return dataMap;
	}
	
	

}
